package com.dc.juc.example._14_threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Description: Executors.newFixedThreadPool(threadNum)
 *
 *  创建一个定长线程池，可控制线程最大并发数，超出的线程会在队列中等待。
 *
 * @author: gdc
 * @date: 2021/8/18
 * @version 1.0
 */
@Slf4j
public class ThreadPool2 {

    public static void main(String[] args){
        ExecutorService threadPool = Executors.newFixedThreadPool(3);

        for (int i = 0; i < 10; i++) {
            int idx = i;
            threadPool.execute(() -> log.info("execute --> {}", idx));
        }

        threadPool.shutdown();
    }
}
